﻿#region License
// Copyright (c) 2009 Shun Chi Guo
// E-Mail:shuncy@gmail.com
// Blog:http://shuncy.cnblogs.com
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using shun.PAPLib.Helper;

namespace shun.PAPLib
{
    public class PushObject
    {
        public PushObject()
        {
        }
        /// <summary>
        /// 消息ID
        /// </summary>
        public string PushID { get; set; }
        /// <summary>
        /// 替换消息ID
        /// </summary>
        public string ReplacePushID { get; set; }
        /// <summary>
        /// 替换方法可选值为pending-only,all
        /// </summary>
        public string ReplaceMethod { get; set; }
        /// <summary>
        /// 必须发送到终端的时间，超过则不继续进行，格式YYYY-MM-DDThh:mm:ssZ
        /// </summary>
        public DateTime DeliverBeforeTimestamp { get; set; }
        /// <summary>
        /// 在指定的时间才能发送，定时时间，格式YYYY-MM-DDThh:mm:ssZ 
        /// </summary>
        public DateTime DeliverAfterTimestamp { get; set; }
        /// <summary>
        /// 内容提供者的文本名称
        /// </summary>
        public string SourceReference { get; set; }
        /// <summary>
        /// 程序提供的通知接收地址
        /// </summary>
        public string PpgNotifyRequestedTo { get; set; }
        /// <summary>
        /// 通知PPG是否想收到进程的日志消息,如果设置true则会在结果包中包含日志信息
        /// </summary>
        public bool ProgressNotesRequested { get; set; }
        private List<string> lsAddress = new List<string>();
        /// <summary>
        /// 接收地址信息
        /// </summary>
        public List<string> Address
        {
            get { return lsAddress; }
            set
            {
                lsAddress.Clear();
                foreach (string val in value)
                {
                    string phone = AddressCheck.CheckNum(val);
                    if (phone != String.Empty)
                    {
                        lsAddress.Add(AddressCheck.ParseNum(phone));
                    }
                }
            }
        }
        
        /// <summary>
        /// 网络信息
        /// </summary>
        public QualityOfService QualityObj { get; set; }

        /// <summary>
        /// 发送者ID
        /// </summary>
        public string SIID { get; set; }
        /// <summary>
        /// 内容类型，可以为SI或SL
        /// </summary>
        public string ContentType { get; set; }

        /// <summary>
        /// 实际的显示内容
        /// </summary>
        public string Content { get; set; }
        /// <summary>
        /// 一个连接地址
        /// </summary>
        public string Url { get; set; }


        /// <summary>
        /// 创建一个默认参数的消息 发送对象
        /// </summary>
        /// <returns></returns>
        public static PushObject CreateDefaultObject(PpgConfig Config)
        {
            PushObject push = new PushObject();
            push.ReplaceMethod = "all";
            push.ReplacePushID = "";
            push.ProgressNotesRequested = Config.ProgressNotesRequested;
            push.PpgNotifyRequestedTo = Config.PpgNotifyRequestedTo;
            push.SourceReference = Config.SourceReference;

            push.QualityObj = new QualityOfService();
            push.QualityObj.Priority = "medium";
            push.QualityObj.DeliveryMethod = Config.DeliveryMethod;
            push.QualityObj.Network = "GSM";
            push.QualityObj.NetworkRequire = true;
            push.QualityObj.Beare = "SMS";
            push.QualityObj.BeareRequire = false;

            push.Address = new List<string>();
            push.ContentType = "SI";
            return push;
        }
    }
}
